package com.wdb.exception;

import org.springframework.util.StringUtils;

/**
 * 实体类自动已经存在报错， 比如用户名新建时已经存在
 *
 * @author: wendaobai@qq.com
 * @date: 2024/3/21 0021 10:59
 */
public class EntityExistException extends RuntimeException {
  public EntityExistException(Class clazz, String field, String val) {
    super(EntityExistException.generateMessage(clazz.getSimpleName(), field, val));
  }

  private static String generateMessage(String entity, String field, String val) {
    return StringUtils.capitalize(entity) + " with " + field + " " + val + " existed";
  }
}
